home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June / CHIP 2006-06.2.iso / program / freeware / ubrowser.exe / ubrowser / app.cpp next >
Encoding:
C/C++ Source or Header  |  2006-02-16  |  4.2 KB  |  142 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  uBrowser - a program that illustrates one way of embedding the
  4. //  Mozilla Gecko (tm) Rendering Engine in an application, grabbing the
  5. //  rendered output and displaying it on the surface of a 3D polygon as
  6. //  texture in an OpenGL (tm) application.
  7. //
  8. //  uBrowser is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 2 of the License, or
  11. //  (at your option) any later version.
  12. //
  13. //  uBrowser is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with uBrowser; if not, write to the Free Software
  20. //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. //
  22. //  Original code:  Copyright 2005 Linden Research Inc.
  23. //                  http://www.lindenlab.com
  24. //
  25. //  Primary author and site maintainer: Callum Prentice (callum@ubrowser.com)
  26. //
  27. //  See contributors.txt or http://ubrowser.com for a list of contributors
  28. //  without whose generous donation of time and effort, this application
  29. //  would not have been possible.
  30. //
  31. ////////////////////////////////////////////////////////////////////////////////
  32. #include "ubrowser.h"
  33.  
  34. #include "GL/glut.h"
  35. #include "glui.h"
  36.  
  37. uBrowser* theUBrowser;
  38.  
  39. ////////////////////////////////////////////////////////////////////////////////
  40. //
  41. void glutReshape( int widthIn, int heightIn )
  42. {
  43.     if ( theUBrowser )
  44.         theUBrowser->reshape( widthIn, heightIn );
  45. };
  46.  
  47. ////////////////////////////////////////////////////////////////////////////////
  48. //
  49. void glutDisplay()
  50. {
  51.     if ( theUBrowser )
  52.         theUBrowser->display();
  53. };
  54.  
  55. ////////////////////////////////////////////////////////////////////////////////
  56. //
  57. void glutIdle()
  58. {
  59.     if ( theUBrowser )
  60.         theUBrowser->idle();
  61. };
  62.  
  63. ////////////////////////////////////////////////////////////////////////////////
  64. //
  65. void glutKeyboard( unsigned char keyIn, int xIn, int yIn )
  66. {
  67.     if ( theUBrowser )
  68.         theUBrowser->keyboard( keyIn, xIn, yIn );
  69. };
  70.  
  71. ////////////////////////////////////////////////////////////////////////////////
  72. //
  73. void glutSpecialKeyboard( int keyIn, int xIn, int yIn )
  74. {
  75.     // appears that you need this defined even if it's empty
  76.     // passing NULL for the handler func ptr crashes this app
  77. };
  78.  
  79. ////////////////////////////////////////////////////////////////////////////////
  80. //
  81. void glutPassiveMouse( int xIn, int yIn )
  82. {
  83.     if ( theUBrowser )
  84.         theUBrowser->passiveMouse( xIn, yIn );
  85. }
  86.  
  87. ////////////////////////////////////////////////////////////////////////////////
  88. //
  89. void glutMouseMove( int xIn , int yIn )
  90. {
  91.     if ( theUBrowser )
  92.         theUBrowser->mouseMove( xIn, yIn );
  93. }
  94.  
  95. ////////////////////////////////////////////////////////////////////////////////
  96. //
  97. void glutMouseButton( int buttonIn, int stateIn, int xIn, int yIn )
  98. {
  99.     if ( theUBrowser )
  100.         theUBrowser->mouseButton( buttonIn, stateIn, xIn, yIn );
  101. }
  102.  
  103. ////////////////////////////////////////////////////////////////////////////////
  104. //
  105. int main( int argc, char* argv[] )
  106. {
  107.     theUBrowser = new uBrowser;
  108.  
  109.     if ( theUBrowser )
  110.     {
  111.         glutInit( &argc, argv );
  112.         glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB );
  113.  
  114.         glutInitWindowPosition( 80, 0 );
  115.         glutInitWindowSize( 1024, 900 );
  116.  
  117.         int appWindow = glutCreateWindow( theUBrowser->getName().c_str() );
  118.  
  119.         glutDisplayFunc( glutDisplay );
  120.  
  121.         GLUI_Master.set_glutReshapeFunc( glutReshape );
  122.         GLUI_Master.set_glutKeyboardFunc( glutKeyboard );
  123.         GLUI_Master.set_glutMouseFunc( glutMouseButton );
  124.         GLUI_Master.set_glutSpecialFunc( glutSpecialKeyboard );
  125.  
  126.         glutPassiveMotionFunc( glutPassiveMouse );
  127.         glutMotionFunc( glutMouseMove );
  128.  
  129.         glutSetWindow( appWindow );
  130.  
  131.         theUBrowser->init( argv[ 0 ], appWindow );
  132.  
  133.         GLUI_Master.set_glutIdleFunc( glutIdle );
  134.  
  135.         glutMainLoop();
  136.  
  137.         if ( theUBrowser )
  138.             delete theUBrowser;
  139.     };
  140.  
  141.     return 1;
  142. }